﻿<%@ Page Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="listusers.aspx.cs" Inherits="admin_user_listusers" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="../stylesheet/admin.css" rel="stylesheet" type="text/css" />
    <link href="../stylesheet/thickbox.css" rel="stylesheet" type="text/css" />
    <script src="../script/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../script/thickbox.js" type="text/javascript"></script>
    <script src="../script/CustomScript.js" type="text/javascript"></script>
    <script src="../script/jquery-ui-1.7.1.custom.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        var startrecordno = 0;
        var lastrecordno = 0;
        var recordsperpage = 3; 
        $(document).ready(function() {

        $("#datascroller1").draggable();
            PageMethod('getAllUsers', ['startrecordno', String(startrecordno)], OngetAllUsersSucceeded, OngetAllUsersFailed);
            PageMethod('UserCount', [], OnUserCountSucceeded, OngetAllUsersFailed);

            $("#savepassword").click(function() {
                PageMethod('changeUserPassword', ['userid', $("#passwordid").text(), 'password', $('#password').val()], OnPasswordSucceeded, OnPasswordFailed);
            });


            $("#datascroller1 #next").click(function() {
            $("#usertable tr td").remove();
            startrecordno = startrecordno + recordsperpage;
                PageMethod('getAllUsers', ['startrecordno', String(startrecordno)], OngetAllUsersSucceeded, OngetAllUsersFailed);
            });

            $("#datascroller1 #first").click(function() {
                $("#usertable tr td").remove();
                startrecordno = 0;
                PageMethod('getAllUsers', ['startrecordno', String(startrecordno)], OngetAllUsersSucceeded, OngetAllUsersFailed);
            });

            $("#datascroller1 #last").click(function() {
            $("#usertable tr td").remove();
                startrecordno = lastrecordno;
                PageMethod('getAllUsers', ['startrecordno', String(startrecordno)], OngetAllUsersSucceeded, OngetAllUsersFailed);
            });
            
            $("#datascroller1 #previous").click(function() {
                startrecordno = startrecordno - recordsperpage;
                $("#usertable tr td").remove();
                PageMethod('getAllUsers', ['startrecordno', String(startrecordno)], OngetAllUsersSucceeded, OngetAllUsersFailed);
            });
        });

        function OnUserCountSucceeded(result, context, method) {
            lastrecordno = Number(result.d) - (Number(result.d) % recordsperpage);
        }

        function OngetAllUsersSucceeded(result, context, method) {
            populateTable(result);

         }

         function OnPasswordSucceeded(result, context, method) {
             displayResult(result.d, "result1");
             clearInput("");
         }


        function OngetAllUsersFailed(result, context, method) {
            
        }
        function OnPasswordFailed(result, context, method) {
        }
        
   
          function setpasswordid(id) {
              setElementValue("passwordid", id);
          }

          function populateTable(result) {

              $(result.d).each(function(i, o) {
                  var status = "";
                  var passwordbutton = "<a onclick='setpasswordid(" + o.UserID + ")' id='a" + o.UserID + "' href='#TB_inline?height=0&width=300&inlineId=passwordform&modal=false' class='thickbox'><img id='i" + o.UserID + "'  title='Change Password' src='../buttons/password.png' /></a>";
                  var editbutton = "<img title='Edit User Details' id=e" + o.UserID + " src='../buttons/useredit.png' />";
                  var deletebutton = "<img title='Delete User' id=d" + o.UserID + " src='../buttons/userdelete.png' />";
                  var activebutton = "<img title='Make User Active' id=a" + o.UserID + " src='../buttons/useractivate.png' />";
                  switch (o.Status) {
                      case 1: // Active
                          status = "<img title='Active User' src='../buttons/useractive.png'/>";
                          activebutton = "";
                          break;
                      case 2: // InActive
                          status = "<img title='In-Active User' src='../buttons/userinactive.png'/>";
                          deletebutton = "";
                          break;
                      case 3:  // Deleted
                          status = "<img title='Deleted User' src='../buttons/userdeleted.png'/>";
                          passwordbutton = "";
                          deletebutton = "";
                          editbutton = "";
                          break;
                  }
                  var rowstring = "<tr><td  >" + o.UserID + "</td><td>" + o.UserName + "</td><td>" + o.FirstName + "</td><td>" + o.LastName + "</td><td>" + o.Email + "</td><td>" + status + "</td><td style='text-align:right;'>" + passwordbutton + editbutton + deletebutton + activebutton + "</tr>";
                  $('#usertable tr:last').after(rowstring);
                  tb_init('a.thickbox, area.thickbox, input.thickbox');


                  /* // button event bind Password Change
                  $("#a" + o.UserID).bind("click", function(e) {
                  changepassword(
                  });

                
                  // button event bind Delete User
                  $("#d" + o.UserID).bind("click", function() {
                  alert(o.UserID + "delete");
                  });
                  
                  // button event bind Edit User
                  $("#e" + o.UserID).bind("click", function() {
                  alert(o.UserID + "edit");
                  });


                  // button event bind Activate User
                  $("#a" + o.UserID).bind("click", function() {
                  alert(o.UserID + "activate");
                  }); */

              });
              $("tr:odd").attr("class", "odd");
              $("tr:even").attr("class", "even");
          }
          </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br/>
<div class="pad20left pad20right"><div id="pagebar"><span class="pad20left bigwhitebold">User List</span></div></div>
<br/>

<div class="inputform1">
<div id="datascroller1" class="datascroller"><span><img src="../buttons/leftds1.jpg" width="15" height="31" /></span>&nbsp;<span><img id="first" src="../buttons/firstds1.jpg" width="28" height="31" /></span>&nbsp;<span><img id="previous" src="../buttons/previousds1.jpg" width="28" height="31" /></span>&nbsp;<span>&nbsp;</span><span><img id="next" src="../buttons/nextds1.jpg" width="28" height="31" /></span>&nbsp;<span><img id="last" src="../buttons/lastds1.jpg" width="28" height="31" /></span>&nbsp;<span><img src="../buttons/rightds1.jpg" width="15" height="31" /></span></div>
<table id="usertable" class="datatable1" cellspacing="0">
<tr><th><img src="../buttons/id1.png" />UserID</th><th><img src="../buttons/username.png" />UserName</th><th><img src="../buttons/name1.png" /> FirstName</th><th><img src="../buttons/name1.png" /> LastName</th><th><img src="../buttons/email1.png" /> E-Mail</th><th><img src="../buttons/status1.png" />Status</th><th><img src="../buttons/action1.png" />Actions</th></tr>
</table>
</div>

<div id="passwordform" style="display:none;" >
<div id="passwordid"></div>
<div class="inputform2">
<table cellspacing="0" class="inputtable2">
<tr><td class="smallboldbluetext" colspan="3">Change Password</td></tr>
<tr><td>Password</td><td>:</td><td><input type="text" id="password" /></td></tr>
<tr><td></td><td></td><td><div class="buttons"><a id="savepassword"  href="#" >Save</a><a onclick="tb_remove();" href="#" >Cancel</a></div></td></tr>
<tr><td></td><td></td ><td id="result1"></td></tr>
</table>
</div>
</div>

<div id="userdetailform" style="display:none;" >
<div class="inputform2">
<table cellspacing="0" class="inputtable2">
<tr><td class="smallboldbluetext" colspan="3">New Password</td></tr>
<tr><td>Email</td><td>:</td><td><input type="text" id="email" /></td></tr>
<tr><td class="smallboldbluetext" colspan="3">User Details</td></tr>
<tr><td>First Name</td><td>:</td><td><input type="text" id="firstname" /></td></tr>
<tr><td>Last Name</td><td>:</td><td><input type="text" id="lastname" /></td></tr>
<tr><td></td><td></td><td><div class="buttons"><a id="SaveUser"  href="#" >Save</a><a href="../dashboard.aspx" >Cancel</a></div></td></tr>
<tr><td></td><td></td><td><div id="resultbox2"><img id="resultimg2" src="" /> <label id="resulttxt2"  ></label></div></td></tr>
</table>
</div>
</div>



</asp:Content>

